package com.qys.livesMall.shop.controller.sys;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.view.BaseQuery;
import com.qys.livesMall.shop.modal.entity.SysPacketEffect;
import com.qys.livesMall.shop.service.SysPacketEffectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 流量包效果表(SysPacketEffect)表控制层
 *
 * @author makejava
 * @since 2023-07-01 17:58:56
 */
@RestController
@RequestMapping("/sysPacketEffect")
@RequiredArgsConstructor
@Tag(name = "sys-流量包效果管理", description = "流量包效果管理")
public class SysPacketEffectController {

    private final SysPacketEffectService sysPacketEffectService;

    /**
     * 分页查询所有数据
     *
     * @param dto 分页对象
     * @return 所有数据
     */
    @PostMapping("/selectAll")
    @Operation(summary = "分页查询所有流量包效果")
    public R<IPage<SysPacketEffect>> selectAll(@RequestBody BaseQuery dto) {
        Page<SysPacketEffect> page = sysPacketEffectService.page(new Page<>(dto.getPageNum(), dto.getPageSize()), Wrappers.query());
        return R.ok(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    @Operation(summary = "根据ID查询流量包效果")
    public R<SysPacketEffect> selectOne(@RequestParam Serializable id) {
        return R.ok(sysPacketEffectService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysPacketEffect 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    @Operation(summary = "新增流量包效果")
    public R<?> insert(@RequestBody SysPacketEffect sysPacketEffect) {
        sysPacketEffectService.save(sysPacketEffect);
        return R.ok();
    }

    /**
     * 修改数据
     *
     * @param sysPacketEffect 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    @Operation(summary = "修改流量包效果")
    public R<?> update(@RequestBody SysPacketEffect sysPacketEffect) {
        sysPacketEffectService.updateById(sysPacketEffect);
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/delete")
    @Operation(summary = "删除流量包效果")
    public R<?> delete(@RequestBody List<Long> idList) {
        sysPacketEffectService.removeByIds(idList);
        return R.ok();
    }
}

